local lijian = fk.CreateSkill({
  name = "mini_mou__lijian",
})

Fk:loadTranslationTable{
  ["mini_mou__lijian"] = "离间",
  [":mini_mou__lijian"] = "出牌阶段限一次，你可以选择至少两名其他角色并弃置X张牌（X为你选择的角色数-2），" ..
  "然后这些角色依次对逆时针最近座次的另一名选择的角色视为使用一张【决斗】。",

  ["#mini_mou__lijian"] = "离间：弃置%arg张牌，令%arg2名角色互相决斗！",

  ["$mini_mou__lijian1"] = "嗯哼，良宵苦短，将军可要好好珍惜。",
  ["$mini_mou__lijian2"] = "软玉在怀，大人还想要些什么？",
}

lijian:addEffect("active", {
  anim_type = "offensive",
  min_card_num = 0,
  min_target_num = 2,
  prompt = function (self, player, selected_cards)
    return "#mini_mou__lijian:::" .. #selected_cards .. ":".. (#selected_cards + 2)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(lijian.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected <= #Fk:currentRoom().alive_players - 2 and not player:prohibitDiscard(to_select)
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected < #selected_cards + 2 and to_select ~= player
  end,
  feasible = function (self, player, selected, selected_cards)
    return #selected > 1 and #selected == #selected_cards + 2
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    if #effect.cards > 0 then
      room:throwCard(effect.cards, lijian.name, player, player)
    end
    local tos = effect.tos
    local targets = table.simpleClone(tos)
    room:sortByAction(tos)
    for _, src in ipairs(tos) do
      if not src.dead then
        if table.contains(targets, src) then
          local dest = src:getNextAlive()
          while not table.contains(tos, dest) do
            dest = dest:getNextAlive()
          end
          if dest == src then break end
          table.removeOne(targets, src)
          room:useVirtualCard("duel", nil, src, dest, lijian.name)
        else
          break
        end
      end
    end
  end,
})

return lijian
